package cn.jiyun.config;

import cn.jiyun.converter.DateConverter;
import cn.jiyun.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 自定义配置类
 */
@Configuration
public class SpringmvcConfig implements WebMvcConfigurer {
    @Override
    public void addFormatters(FormatterRegistry registry) {
        //将自定义注册器交由springmvc管理
        registry.addConverter(new DateConverter());
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //将自定义拦截器注册到springmvc拦截器链中，并配置拦截规则
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**");
    }
}
